<template>
    <view>
        <view v-if="detail != null">
            <!-- 地址 -->
            <view v-if="detail.order_model == 0 || detail.order_model == 2" class="address bg-white spacing-mb">
                <view class="address-base oh">
                    <text v-if="(detail.address_data.alias || null) != null" class="address-alias">{{ detail.address_data.alias }}</text>
                    <text>{{ detail.address_data.name }}</text>
                    <text class="fr">{{ detail.address_data.tel }}</text>
                </view>
                <view class="address-detail oh">
                    <image class="icon fl" src="@/static/images/user-address.png" mode="widthFix" />
                    <view class="text fr">
                        {{ detail.address_data.province_name }}{{ detail.address_data.city_name }}{{ detail.address_data.county_name }}{{ detail.address_data.address }}
                    </view>
                </view>
            </view>

            <!-- 商品列表 -->
            <view class="goods bg-white spacing-mb">
                <view class="goods-item br-b-dashed oh" v-for="(item, index) in detail.items" :key="index">
                    <navigator :url="'/pages/goods-detail/goods-detail?goods_id=' + item.goods_id" hover-class="none">
                        <image class="goods-image fl" :src="item.images" mode="aspectFill" />
                        <view class="goods-base">
                            <view class="goods-title multi-text">{{ item.title }}</view>
                            <block v-if="item.spec != null">
                                <view class="goods-attribute cr-888" v-for="(spec, index1) in item.spec" :key="index1">{{ spec.type }}:{{ spec.value }}</view>
                            </block>
                        </view>
                        <view class="oh goods-price">
                            <text class="sales-price">{{ price_symbol }}{{ item.price }}</text>
                            <text v-if="item.original_price > 0" class="original-price">{{ price_symbol }}{{ item.original_price }}</text>
                            <text class="buy-number">x{{ item.buy_number }}</text>
                        </view>
                    </navigator>
                </view>
                <view class="order-describe">{{ detail.describe }}</view>
            </view>

            <!-- 快递数据 -->
            <view v-if="express_info != []" class="panel-item spacing-mt">
                <view class="panel-title">
                    <image class="exp-image" :src="express_info.logo" mode="aspectFill" />
                    <view class="exp-title">
                        <view class="exp-title-cc">{{ express_info.expName }}</view>
                        <view class="exp-num">
                            {{ express_info.number }}
                            <button type="primary" :plain="true" hover-class="none" size="mini" class="dis-block wh-auto" @click="copy_event">复制</button>
                        </view>
                    </view>
                    <view class="exp-status">{{ express_info.deliverystatus_text }}</view>
                </view>
                <view class="panel-content bg-white">
                    <view class="item" v-for="(item, index) in express_info.list" :key="index">
                        <view class="dian"></view>

                        <view class="content">{{ item.status }}</view>

                        <view class="title">{{ item.time }}</view>
                    </view>
                </view>
            </view>

            <!-- parse <template is="bottom_line" :data="status: data_bottom_line_status"></template> -->
            <block name="bottom_line">
                <view v-if="data_bottom_line_status || false" class="data-bottom-line">
                    <view class="left fl"></view>
                    <view class="msg fl">我是有底线的</view>
                    <view class="right fr"></view>
                </view>
            </block>
        </view>

        <view v-if="detail == null">
            <!-- parse <template is="nodata" :data="status: data_list_loding_status, msg: data_list_loding_msg"></template> -->
            <block name="nodata">
                <!-- 1 加载中 -->
                <view v-if="data_list_loding_status == 1" class="no-data-loding tc">
                    <text>加载中...</text>
                </view>

                <!-- 2 处理错误 -->
                <view v-else-if="data_list_loding_status == 2" class="no-data-box tc">
                    <image src="@/static/images/common/error.png" mode="widthFix" />
                    <view class="no-data-tips">{{ data_list_loding_msg || '处理错误' }}</view>
                </view>

                <!-- 0 默认没有数据 -->
                <view v-else-if="data_list_loding_status == 0" class="no-data-box tc">
                    <image src="@/static/images/common/empty.png" mode="widthFix" />
                    <view class="no-data-tips">{{ data_list_loding_msg || '没有相关数据' }}</view>
                </view>
            </block>
        </view>
    </view>
</template>

<script>
const app = getApp();
export default {
    data() {
        return {
            price_symbol: app.globalData.data.price_symbol,
            params: null,
            data_list_loding_status: 1,
            data_list_loding_msg: '',
            data_bottom_line_status: false,
            detail: null,
            express_info: [],
            alias: '',
            name: '',
            tel: '',
            province_name: '',
            city_name: '',
            county_name: '',
            address: '',

            spec: {
                type: '',
                value: ''
            }
        };
    },
    onLoad(params) {
        //params['order_id'] = 3;
        this.setData({
            params: params
        });
        this.init();
    },
    onShow() {
        uni.setNavigationBarTitle({
            title: '物流信息'
        });
    },
    // 下拉刷新
    onPullDownRefresh() {
        this.init();
    },
    methods: {
        init() {
            var self = this;
            uni.showLoading({
                title: this.$t('common.loading_in_text'),
            });
            this.setData({
                data_list_loding_status: 1
            });
            uni.request({
                url: app.globalData.get_request_url('index', 'index', 'aliexpress'),
                method: 'POST',
                data: {
                    order_id: this.params.order_id,
                    express_id: this.params.express_id,
                    express_number: this.params.express_number,
                    type: 1,
                    tablename: 'PluginsGroupsplusOrderAddress'
                },
                dataType: 'json',
                success: (res) => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    console.log(res);

                    if (res.data.code == 0) {
                        var data = res.data.data;
                        self.setData({
                            express_info: data,
                            data_list_loding_status: 3,
                            data_bottom_line_status: true,
                            data_list_loding_msg: ''
                        });
                    } else {
                        self.setData({
                            data_list_loding_status: 2,
                            data_bottom_line_status: false,
                            data_list_loding_msg: res.data.msg
                        });

                        if (app.globalData.is_login_check(res.data, self, 'init')) {
                            app.globalData.showToast(res.data.msg);
                        }
                    }
                },
                fail: () => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    self.setData({
                        data_list_loding_status: 2,
                        data_bottom_line_status: false,
                        data_list_loding_msg: this.$t('common.internet_error_tips')
                    });
                    app.globalData.showToast(this.$t('common.internet_error_tips'));
                }
            });
            this.get_order_info();
        },

        // 拿订单信息
        get_order_info() {
            var self = this;
            uni.showLoading({
                title: this.$t('common.loading_in_text'),
            });
            this.setData({
                data_list_loding_status: 1
            });
            uni.request({
                url: app.globalData.get_request_url('OrderDetail', 'index', 'groupsplus'),
                method: 'POST',
                data: {
                    id: this.params.order_id
                },
                dataType: 'json',
                success: (res) => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();

                    if (res.data.code == 0) {
                        var data = res.data.data;
                        self.setData({
                            detail: data.data,
                            data_list_loding_status: 3,
                            data_bottom_line_status: true,
                            data_list_loding_msg: ''
                        });
                    } else {
                        self.setData({
                            data_list_loding_status: 2,
                            data_bottom_line_status: false,
                            data_list_loding_msg: res.data.msg
                        });

                        if (app.globalData.is_login_check(res.data, self, 'init')) {
                            app.globalData.showToast(res.data.msg);
                        }
                    }
                },
                fail: () => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    self.setData({
                        data_list_loding_status: 2,
                        data_bottom_line_status: false,
                        data_list_loding_msg: this.$t('common.internet_error_tips')
                    });
                    app.globalData.showToast(this.$t('common.internet_error_tips'));
                }
            });
        },

        // 复制单号
        copy_event(e) {
            uni.setClipboardData({
                data: this.express_info.number,

                success(res) {
                    app.globalData.showToast('复制成功', 'success');
                }
            });
        }
    }
};
</script>
<style>
@import './orderexpress.css';
</style>
